<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :circular="true">
			<swiper-item v-for="(item, i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, i) in navList" :key="i" @click="navClickHandle(item)">
				<image class="nav-img" :src="item.image_src"></image>
			</view>
		</view>

		<!-- 楼层区域 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item, i) in floorList" :key="i">
				<!-- 楼层标题 -->
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<!-- 楼层图片区域 -->
				<view class="floor-img">
					<!-- 左侧大图片 -->
					<view class="floor-left-img">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</view>
					<!-- 右侧四个小图片 -->
					<view class="right-img-box">
						<view v-for="(item2,i2) in item.product_list" :key="i2">
							<navigator class="floor-right-img" v-if="i2 != 0" :url="item2.url">
								<image :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix">
								</image>
							</navigator>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		showMsg
	} from '../../utils/common.js'
	export default {
		data() {
			return {
				swiperList: [], //轮播图列表数据
				navList: [], //分类导航数据列表
				floorList: [], //楼层数据列表
			};
		},

		onLoad() {
			// 调用获取轮播图数据方法
			this.getSwiper()
			// 调用获取分类导航数据方法
			this.getNavList()
			// 调用获取楼层数据的方法
			this.getFloorList()
		},

		methods: {
			// 获取轮播图方法
			async getSwiper() {
				const data = await uni.$http.get('/home/swiperdata')
				// console.log(data)
				if (data.data.meta.status != 200) {
					return showMsg()
				}
				this.swiperList = data.data.message
			},
			// 获取分类导航数据方法
			async getNavList() {
				const data = await uni.$http.get('/home/catitems')
				if (data.data.meta.status != 200) {
					return showMsg()
				}
				this.navList = data.data.message
			},
			// 获取楼层数据方法
			async getFloorList() {
				const data = await uni.$http.get('/home/floordata')
				console.log(data)
				if (data.data.meta.status != 200) {
					return showMsg()
				}
				// 对url数据进行处理
				data.data.message.forEach(floor => {
					floor.product_list.forEach(item => {
						item.url = '/subpkg/goods_list/goods_list?' + item.navigator_url.split('?')[1]
					})
				})
				this.floorList = data.data.message
				console.log(this.floorList)
			},
			// nav-item被点击时的事件处理
			navClickHandle(item) {
				if (item.name == '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-item {
			image {
				width: 100%;
				// height: 100%;
			}
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 32rpx 0;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-title {
		height: 60rpx;
		width: 100%;
	}

	.floor-img {
		display: flex;
		padding-left: 10px;
	}

	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
</style>
